package interceptor;

import java.util.Map;

import vo.User;
import business.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 定义权限检查拦截器
 * 
 * @author lijunjie
 * 
 */
public class AuthorityInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 7367211037602072409L;
	private UserService userService;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();
		Map session = ctx.getSession();
		String username = (String) session.get("username");
		User user = userService.getByName(username);
		if (username != null && user != null) {
			return invocation.invoke();
		}
        
		return "login";
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
